tg-me.com/python_codes/259
Create:
Last Update:
Last Update:
common techniques for using the type() function in Python:
Get the type of an object:
my_object = "Hello, world!"Check if an object is of a given type:
my_type = type(my_object)
my_object = "Hello, world!"Create a new object of a given type:
if type(my_object) == str:
print("my_object is a string.")
my_type = intUse the type of an object as a dictionary key:
my_object = my_type("1")
my_object = "Hello, world!"Use the type of an object as a set element:
my_type = type(my_object)
my_dict = {}
my_dict[my_type] = my_object
my_object = "Hello, world!"The type() function is a built-in function in Python that is used to determine the type of an object. It is a useful tool for checking the type of an object, creating objects of a specific type, and using the type of an object as a key in a dictionary or set.
my_type = type(my_object)
my_set = set()
my_set.add(my_type)
Share and Support
@Python_Codes
BY Python Codes
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/python_codes/259